#include <iostream>
#include <opencv2/opencv.hpp>
#include <vector>

using namespace cv;
using namespace std;

int main()
{
    // 1 显示一张图片
    /*
    Mat img = imread("C:/Users/zengye/Pictures/R-C.jpg");
    imshow("mm", img);
    waitKey(0);  //在指定的时间内等待用户按下按键
    */

    // 2 图片上画红色方框
    /*
    Mat img = imread("C:/Users/zengye/Pictures/R-C.jpg");
    rectangle(img, Rect(200, 100, 350, 450), Scalar(0, 0, 255), 3);
    imshow("mm", img);
    waitKey(0);
    */

    // 3 显示一个视频
    /*
    VideoCapture cap = VideoCapture("C:/Users/zengye/Pictures/singing.mp4");
    Mat img;
    while(cap.read(img)) // 循环读取视频里的每一帧 保存在img
    {
        // 4 视频里面画框
        rectangle(img,Rect(200,100,250,450),Scalar(0,0,255),3);
        imshow("video", img);
        waitKey(30);
    }
    waitKey(0);  //在指定的时间内等待用户按下按键
    */

    // 4 图片加载图片
    vector<Rect> face;
    CascadeClassifier object;
    // 加载harr分类器
    object.load("D:/study/qt/day02/haarcascade_frontalface_alt.xml");

    Mat img = imread("C:/Users/zengye/Pictures/R-C.jpg");
    Mat imgJiao = imread("D:/study/qt/day02/horn.png");

    // 识别位置
    object.detectMultiScale(img, face);

    int x = 10;
    int y = 10;
    int jiaoWidth = imgJiao.cols;
    int jiaoHeight = imgJiao.rows;
    if (!face.empty()) {
        x = face[0].tl().x;
        y = face[0].tl().y - jiaoHeight / 2;
    }



    printf("dd c %d",jiaoWidth);
    printf("dd r %d",jiaoHeight);

    // 定义区域
    Mat imgROI;
    imgROI = img(Rect(x,y,jiaoWidth,jiaoHeight)); // 设置区域 img 原图片
    addWeighted(imgROI, 1.0, imgJiao, 1,0,imgROI); // 进行添加

    imshow("mm", img);
//    imshow("imgJiao", imgJiao);

    waitKey(0);  //在指定的时间内等待用户按下按键

    cout << "Hello World!" << endl;
    return 0;
}
